package com.easy.common.constant;
import java.util.*;

import com.easy.common.util.Utility;

public class RegistProps {
	private static Map props = null;

	public RegistProps()
	{
	}

	public static boolean isEmpty()
	{
		if(props!=null){
			Iterator iter = props.entrySet().iterator();
			while (iter.hasNext()) {
				Map.Entry entry = (Map.Entry) iter.next();
				String key = (String) entry.getKey();
				String val = (String) entry.getValue();
			}
		}
		return props == null || props.size() < 1;
	}

	public static String getProp(String key)
	{
		if (props == null)
			return "";
		String prop = (String)props.get(key);
		if (prop != null)
			prop = prop.trim();
		else
			prop = "";
		return prop;
	}

	public static String getString(String key)
	{
		return getProp(key);
	}

	public static int getInt(String key)
	{
		int rtInt = 0;
		try
		{
			String strValue = getString(key);
			if (!Utility.isNullorEmpty(strValue))
				rtInt = Integer.parseInt(strValue);
		}
		catch (Exception exception) { }
		return rtInt;
	}

	public static long getLong(String key)
	{
		long rtLong = 0L;
		try
		{
			String strValue = getString(key);
			if (!Utility.isNullorEmpty(strValue))
				rtLong = Long.parseLong(strValue);
		}
		catch (Exception exception) { }
		return rtLong;
	}

	public static void clear(String postFix)
	{
		if (props != null)
			Utility.clearMapPost(props, postFix);
	}

	public static void clear()
	{
		if (props != null)
		{
			props.clear();
			props = null;
		}
	}

	public static void setProps(Map aProps)
	{
		clear();
		props = aProps;
	}

	public static void updateProp(String key, String value)
	{
		props.put(key, value);
	}

	public static void addProps(Map aProps)
	{
		if (aProps == null)
			return;
		if (props == null)
			props = new HashMap();
		String key;
		String value;
		for (Iterator iKeys = aProps.keySet().iterator(); iKeys.hasNext(); props.put(key, value))
		{
			key = (String)iKeys.next();
			value = (String)aProps.get(key);
			//System.out.println("key="+key+ "  value="+value);
		}

	}
}
